#include "../../source/util.h"

void serialize_test()
{
    Json::Value val;
    val["name"] = "zhangsan";
    val["age"] = 18;
    val["score"].append(77.5);
    val["score"].append(88.5);
    val["score"].append(99.5);
    auto ret = biteutil::JSON::serialize(val);
    if(!ret)
    {
        return;
    }
    std::cout << *ret << std::endl;
}

void unserialize_test()
{
    std::string input = R"({"name":"zhangsan","age":18,"score":[77.5,88.5,99.5]})";
    auto ret = biteutil::JSON::unserialize(input);
    if(!ret)
    {
        return;
    }
    std::cout << (*ret)["name"].asString() << std::endl;
    std::cout << (*ret)["age"].asInt() << std::endl;
    if(!(*ret)["score"].isNull() && (*ret)["score"].isArray())
    {
        int sz = (*ret)["score"].size();
        for(int i = 0; i < sz; i++)
        {
            std::cout << (*ret)["score"][i].asDouble() << std::endl;
        }
    }
}
int main()
{
    serialize_test();
    unserialize_test();
    return 0;
}